/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2009, Around(J2)ME				                                 **
 **   All rights reserved.                                                   **
 **                                                                          **
 **   This program and the accompanying materials are made available under   **
 **   the terms of the New BSD License which accompanies this    			 **
 **   distribution.											                 **
 **   A copy is found in the textfile LICENSE.txt							 **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Main developers:                                                       **
 **     Juri Strumpflohner		http://blog.js-development.com	             **
 **		Matthias Braunhofer		http://matthias.jimdo.com                    **
 **                                                                          **
 **  **********************************************************************  */

package com.firstlife.mps.unittests;

import j2meunit.framework.Test;
import j2meunit.framework.TestCase;
import j2meunit.framework.TestMethod;
import j2meunit.framework.TestSuite;

import java.io.IOException;

import javax.microedition.rms.RecordStoreException;

import com.aroundj2me.model.Preferences;

public class PreferencesTest extends TestCase {
	private Preferences preferences;
	private String key;
	private String value;
	
	public PreferencesTest() {
	}
	
	public PreferencesTest(String name, TestMethod method) {
		super(name, method);
	}
	
	protected void setUp() throws Exception {
		preferences = new Preferences();
		key = "testKey";
		value = "testValue";
	}
	
	protected void tearDown() throws Exception {
		preferences = null;
		key = null;
		value = null;
	}
	
	public void testPut() throws RecordStoreException {
		preferences.put(key, value);
		preferences.save();
		assertTrue("Preferences should contain key", preferences.get(key) != null);
	}
	
	public void testGet() {
		assertEquals("Key should contain correct value", preferences.get(key), value);
	}
	
	public Test suite() {
		TestSuite aSuite = new TestSuite();
		aSuite.addTest(new PreferencesTest("PreferencesTest:testPut", new TestMethod() { 
			public void run(TestCase tc) throws IOException, RecordStoreException {
				((PreferencesTest) tc).testPut(); 
			} 
		}));
		aSuite.addTest(new PreferencesTest("PreferencesTest:testGet", new TestMethod() { 
			public void run(TestCase tc) throws IOException {
				((PreferencesTest) tc).testGet(); 
			} 
		}));
		return aSuite;
	}
}
